package com.demo.shiroDemo10.web;

import java.util.List;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.demo.shiroDemo10.model.User;
import com.demo.shiroDemo10.utils.CommonResult;

@RestController
@RequestMapping("/user")
public class UserController {
	
	@RequestMapping("/list")
	public Object list() {
		CommonResult<List<User>> result = new CommonResult<>();
		result.setData(User.USERS);
		return result;
	}

	@RequestMapping("/{id}")
	public Object one(@PathVariable("id") Integer id) {
		CommonResult<User> result = new CommonResult<>();
		result.setData(User.USER_MAP.get(id));
		return result;
	}

	@RequestMapping(value="/add", method={RequestMethod.POST})
	public Object add(String username,String password) {
		CommonResult<User> result = new CommonResult<>();
		result.setData(User.addUser(username, password));
		return result;
	}
	
}
